package com.heyqing.topic.StrStr_0028;

import java.util.Scanner;

/**
 * ClassName:StrStr
 * Package:com.heyqing.topic.StrStr_0028
 * Description:
 *
 * @Date:2024/9/9
 * @Author:Heyqing
 */
public class StrStr {
    /**
     * 找出字符串中第一个匹配项的下标
     *
     * @param haystack
     * @param needle
     * @return
     */
    public int strStr(String haystack, String needle) {
        return haystack.indexOf(needle);
    }

    public static void start() {
        StrStr strStr = new StrStr();
        Scanner sc = new Scanner(System.in);
        System.out.println("haystack");
        String haystack = sc.nextLine();
        System.out.println("needle");
        String needle = sc.nextLine();
        int i = strStr.strStr(haystack, needle);
        System.out.println("开始下标为：" + i);
    }
}
